<template>
  <div class="schedule-checkup">
    <!-- 头部 -->
    <el-container style="height: 100%; border: 1px solid #eee">
      <el-header style="height: 60px; line-height: 60px; background-color: #409EFF; color: #fff; padding-left: 20px; display: flex; justify-content: space-between; align-items: center;">
        <span><i class="el-icon-house"></i> 熙心健康管理系统</span>
        <div style="display: flex; align-items: center;">
          <span style="margin-right: 20px;">系统管理员：{{ userName }}</span>
          <el-button type="danger" size="small" @click="logout">退出</el-button>
        </div>
      </el-header>
      <el-container>
        <!-- 侧边栏 -->
        <el-aside width="200px" style="background-color: #333; color: #fff;">
          <el-menu :default-active="activeIndex" class="el-menu-vertical-demo" @select="handleSelect" background-color="#333" text-color="#fff" active-text-color="#409EFF">
            <el-menu-item index="1">
              <i class="el-icon-house"></i>
              <router-link to="/first">首页</router-link>
            </el-menu-item>
            <el-menu-item index="2">
              <i class="el-icon-date"></i>
              <router-link to="/emp">体检预约</router-link>
            </el-menu-item>
            <el-menu-item index="3">
              <i class="el-icon-s-order"></i>
              <router-link to="/dept">预约列表</router-link>
            </el-menu-item>
            <el-menu-item index="4">
              <i class="el-icon-search"></i>
              <router-link to="/find">体检客户查询</router-link>
            </el-menu-item>
          </el-menu>
        </el-aside>

        <!-- 主内容区 -->
        <el-main style="padding: 20px;">
          <!-- 面包屑导航 -->
          <el-breadcrumb separator="/">
            <el-breadcrumb-item>预约</el-breadcrumb-item>
            <el-breadcrumb-item>体检预约</el-breadcrumb-item>
          </el-breadcrumb>

          <!-- 页面主要内容 -->
          <el-card class="box-card">
            <!-- 标题 -->
            <h2>基本信息</h2>
            <!-- 表单 -->
            <el-form :model="form" :rules="rules" ref="formRef" label-width="100px">
              <el-row :gutter="20">
                <!-- 体检单号 -->
                <el-col :span="6">
                  <el-form-item label="体检单号" prop="checkupId">
                    <el-input v-model="form.checkupId" :disabled="true"></el-input>
                  </el-form-item>
                </el-col>
                <!-- 姓名 -->
                <el-col :span="6">
                  <el-form-item label="姓名" prop="name">
                    <el-input v-model="form.name" placeholder="输入姓名"></el-input>
                  </el-form-item>
                </el-col>
                <!-- 性别 -->
                <el-col :span="6">
                  <el-form-item label="性别" prop="gender">
                    <el-select v-model="form.gender" placeholder="选择性别">
                      <el-option label="男" value="男"></el-option>
                      <el-option label="女" value="女"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <!-- 出生日期 -->
                <el-col :span="6">
                  <el-form-item label="出生日期" prop="birthday">
                    <el-date-picker
                      v-model="form.birthday"
                      type="date"
                      placeholder="选择出生日期"
                      value-format="yyyy-MM-dd"
                    ></el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <!-- 手机号 -->
                <el-col :span="6">
                  <el-form-item label="手机号" prop="phoneNumber">
                    <el-input v-model="form.phoneNumber" placeholder="输入手机号"></el-input>
                  </el-form-item>
                </el-col>
                <!-- 身份证号 -->
                <el-col :span="6">
                  <el-form-item label="身份证号" prop="idNumber">
                    <el-input v-model="form.idNumber" placeholder="输入身份证号码"></el-input>
                  </el-form-item>
                </el-col>
                <!-- 家庭住址 -->
                <el-col :span="12">
                  <el-form-item label="家庭住址" prop="address">
                    <el-input v-model="form.address" placeholder="输入通讯地址"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-card>

          <!-- 预约信息 -->
          <el-card class="box-card">
            <h2>预约信息</h2>
            <el-form :model="form" :rules="rules" ref="formRef" label-width="100px">
              <el-form-item label="预约院区" prop="hospital">
                <el-select v-model="form.hospital" placeholder="选择院区地址" @change="selectHospital">
                  <el-option
                    v-for="(item, index) in hospitalList"
                    :key="index"
                    :label="item.name"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="院区描述" prop="hospitalDescription">
                <p>{{ form.hospitalDescription }}</p>
              </el-form-item>
            </el-form>
          </el-card>

          <!-- 预约详情 -->
          <el-card class="box-card">
            <h2>预约详情</h2>
            <el-form :model="form" :rules="rules" ref="formRef" label-width="100px">
              <el-row :gutter="20">
                <!-- 预约类型 -->
                <el-col :span="6">
                  <el-form-item label="预约类型" prop="appointmentType">
                    <el-select v-model="form.appointmentType" placeholder="选择预约类型">
                      <el-option label="在线预约" value="在线预约"></el-option>
                      <el-option label="电话预约" value="电话预约"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <!-- 预约套餐 -->
                <el-col :span="6">
                  <el-form-item label="预约套餐" prop="package">
                    <el-select v-model="form.package" placeholder="选择预约套餐" @change="calculatePrice">
                      <el-option
                        v-for="(item, index) in packageList"
                        :key="index"
                        :label="item.name"
                        :value="item.id"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <!-- 体检时间 -->
                <el-col :span="6">
                  <el-form-item label="体检时间" prop="examDate">
                    <el-date-picker
                      v-model="form.examDate"
                      type="date"
                      placeholder="选择体检时间"
                      value-format="yyyy-MM-dd"
                    ></el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <!-- 体检时段 -->
                <el-col :span="6">
                  <el-form-item label="体检时段" prop="examTimeSlot">
                    <el-select v-model="form.examTimeSlot" placeholder="选择体检时段">
                      <el-option label="上午场" value="上午场"></el-option>
                      <el-option label="下午场" value="下午场"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <!-- 套餐价格 -->
                <el-col :span="6">
                  <el-form-item label="套餐价格" prop="packagePrice">
                    <el-input v-model="form.packagePrice" disabled></el-input>
                  </el-form-item>
                </el-col>
                <!-- 优惠补贴 -->
                <el-col :span="6">
                  <el-form-item label="优惠补贴" prop="discount">
                    <el-input v-model="form.discount" disabled></el-input>
                  </el-form-item>
                </el-col>
                <!-- 结算金额 -->
                <el-col :span="6">
                  <el-form-item label="结算金额" prop="totalPrice">
                    <el-input v-model="form.totalPrice" disabled></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <!-- 结算类别 -->
                <el-col :span="6">
                  <el-form-item label="结算类别" prop="paymentMethod">
                    <el-select v-model="form.paymentMethod" placeholder="选择结算类别">
                      <el-option label="现金支付" value="现金支付"></el-option>
                      <el-option label="微信支付" value="微信支付"></el-option>
                      <el-option label="支付宝支付" value="支付宝支付"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-card>

          <!-- 提交按钮 -->
          <el-row :gutter="20">
            <el-col :span="24" style="text-align: center">
              <el-button type="primary" @click="submitForm">预约</el-button>
              <el-button @click="resetForm">清空</el-button>
            </el-col>
          </el-row>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: 'ScheduleCheckup',
  data() {
    return {
      userName: 'admin',
      activeIndex: '2', // 默认激活第二个菜单项（体检预约）
      form: {
        checkupId: '20231008990202120',
        name: '',
        gender: '',
        birthday: '',
        phoneNumber: '',
        idNumber: '',
        address: '',
        hospital: '',
        hospitalDescription: '',
        appointmentType: '',
        package: '',
        packagePrice: 0,
        discount: 0,
        totalPrice: 0,
        examDate: '',
        examTimeSlot: '',
        paymentMethod: '',
      },
      rules: {
        name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
        gender: [{ required: true, message: '请选择性别', trigger: 'change' }],
        birthday: [{ required: true, message: '请选择出生日期', trigger: 'change' }],
        phoneNumber: [
          { required: true, message: '请输入手机号', trigger: 'blur' },
          {
            pattern: /^1[3456789]\d{9}$/,
            message: '手机号格式不正确',
            trigger: 'blur',
          },
        ],
        idNumber: [
          { required: true, message: '请输入身份证号码', trigger: 'blur' },
          {
            pattern: /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9Xx])$/,
            message: '身份证号码格式不正确',
            trigger: 'blur',
          },
        ],
        hospital: [{ required: true, message: '请选择预约院区', trigger: 'change' }],
        appointmentType: [{ required: true, message: '请选择预约类型', trigger: 'change' }],
        package: [{ required: true, message: '请选择预约套餐', trigger: 'change' }],
        examDate: [{ required: true, message: '请选择体检时间', trigger: 'change' }],
        examTimeSlot: [{ required: true, message: '请选择体检时段', trigger: 'change' }],
        paymentMethod: [{ required: true, message: '请选择结算类别', trigger: 'change' }],
      },
      hospitalList: [
        { id: 1, name: '浑南院区' },
        { id: 2, name: '市府广场院区' },
        { id: 3, name: '三好街院区' },
      ],
      packageList: [
        { id: 1, name: '基础套餐', price: 1500, discount: 400 },
        { id: 2, name: '豪华套餐', price: 2500, discount: 600 },
        { id: 3, name: '至尊套餐', price: 3500, discount: 800 },
      ],
    };
  },
  methods: {
    logout() {
      this.$message.success('退出成功！');
      this.$router.push('/login');
    },
    // 提交表单
    submitForm() {
      this.$refs.formRef.validate((valid) => {
        if (valid) {
          // 提交表单逻辑
          this.$message.success('预约成功！');
        } else {
          this.$message.error('请填写完整信息！');
        }
      });
    },
    // 重置表单
    resetForm() {
      this.$refs.formRef.resetFields();
    },
    // 选择院区
    selectHospital(hospitalId) {
      const hospital = this.hospitalList.find((item) => item.id === hospitalId);
      if (hospital) {
        this.form.hospitalDescription = `
          营业时间：周一至周六 7:30-11:30
          采血截止：10:30
          联系电话：4006297568
          地址：沈阳市浑南区创新路175号（智慧大街交互处）
        `;
      }
    },
    // 选择套餐并计算价格
    calculatePrice(packageId) {
      const packages = this.packageList.find((item) => item.id === packageId);
      if (packages) {
        this.form.packagePrice = packages.price;
        this.form.discount = packages.discount;
        this.form.totalPrice = packages.price - packages.discount;
      }
    },
    handleSelect(index) {
      this.activeIndex = index;
    },
  },
};
</script>

<style scoped>
.schedule-checkup {
  height: 100vh;
  display: flex;
}

.box-card {
  margin-bottom: 20px;
  background-color: #fff;
  border-radius: 5px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.box-card h2 {
  margin: 0;
  font-size: 24px;
  color: #333;
}

.el-header {
  background-color: #409EFF;
  color: #fff;
}

.el-aside {
  background-color: #333;
  color: #fff;
}

.el-main {
  background-color: #f0f2f5;
}

.el-menu {
  border-right: none;
}

.el-menu-item a {
  color: #fff;
  text-decoration: none;
}

.el-menu-item a:hover {
  color: #409EFF;
}

.el-menu-item.is-active a {
  color: #409EFF;
  font-weight: bold;
}

.el-menu-item.is-active {
  background-color: #4a4a4a;
}

.el-breadcrumb {
  margin-bottom: 20px;
}

.el-form-item__label {
  font-weight: bold;
}

.el-button {
  margin-top: 10px;
}

/* 表单输入框样式 */
.el-input__inner {
  border-radius: 5px;
}

/* 选择框样式 */
.el-select .el-input__inner {
  border-radius: 5px;
}

/* 日期选择器样式 */
.el-date-editor.el-input__inner {
  border-radius: 5px;
}

/* 提交按钮样式 */
.el-button--primary {
  margin-right: 20px;
}

/* 清空按钮样式 */
.el-button--default {
  margin-left: 20px;
}
</style>
